<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>User Information</title>
</head>

<body>

<?php if (!isset($_POST['submit'])) { exit('permission denied!'); } ?>

<?php
$id      = $_POST['id'];
$website = $_POST['website'];
$online  = $_POST['online'];
if (strcmp($online, "All day") == 0) {
    $online = null;
}
include('conn.php');
mysql_query( "UPDATE user SET `website` = '$website', `online` = '$online' WHERE `id` = $id" )
    or die("UPDATE failed");

echo "<h2>User Information Update Success</h2>";
$user_query = mysql_query( "SELECT * FROM user WHERE `id` = $id LIMIT 1")
    or die("SELECT failed");
if (!$user = mysql_fetch_array($user_query)) {
    die('cannot fetch array from $user_query');
} else {
?>
<table width="60%" border="1">
    <tr>
        <th width="30%" bgcolor="#CCCCCC" scope="col">学号</th>
        <td width="30%"><?php echo $user[0]; ?></td>
    </tr>
    <tr>
        <th width="30%" bgcolor="#CCCCCC" scope="col">姓名</th>
        <td width="30%"><?php echo $user[1]; ?></td>
    </tr>
    <tr>
        <th width="30%" bgcolor="#CCCCCC" scope="col">网站</th>
        <td width="30%"><?php if ($user[2] != null) { echo $user[2]; } ?></td>
    </tr>
    <tr>
        <th width="30%" bgcolor="#CCCCCC" scope="col">在线时间</th>
        <td width="30%">
<?php if ($user[2] != null && $user[3] == null) {
    echo '全天';
} else if ($user[3] != null) {
    echo $user[3];
} ?>
        </td>
    </tr>
    <tr>
        <th width="30%" bgcolor="#CCCCCC" scope="col">得到票数</th>
        <td width="30%"><?php echo $user[4]; ?></td>
    </tr>
    <tr>
        <th width="30%" bgcolor="#CCCCCC" scope="col">投出票数</th>
        <td width="30%"><?php echo $user[5]; ?></td>
    </tr>
</table>
<?php } ?>

<p><a href="show.php">查看学生网站及投票结果</a></p>
<p><a href="index.html">返回登录页面</a></p>
</body>
